using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using PhongKham.Class;

namespace PhongKham
{
    public partial class FrmChSQL : DevExpress.XtraEditors.XtraForm
    {
        private Chuoi.EncryptDecrypt ed = new Chuoi.EncryptDecrypt();
        public FrmChSQL()
        {
            InitializeComponent();
        }

        private void btnArr_btnEventUpdate_click(object sender, EventArgs e)
        {
            System.Data.SqlClient.SqlConnection connTemp = new System.Data.SqlClient.SqlConnection();

            try
            {
                connTemp.ConnectionString = "Password=" + txtPass.Text.Trim() +
                                            ";User ID=" + txtUsename.Text.Trim() +
                                            ";Initial Catalog=" + txtCsdl.Text.Trim() +
                                            ";Data Source=" + txtHost.Text.Trim();
                connTemp.Open();
            }
            catch
            {
                MessageBox.Show("Không thể kết nối đến server!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            global::PhongKham.Properties.Settings.Default.m_username = ed.EncryptText(txtUsename.Text.Trim());
            global::PhongKham.Properties.Settings.Default.m_database = ed.EncryptText(txtCsdl.Text.Trim());
            global::PhongKham.Properties.Settings.Default.m_server = ed.EncryptText(txtHost.Text.Trim());
            global::PhongKham.Properties.Settings.Default.m_password = ed.EncryptText(txtPass.Text.Trim());
            global::PhongKham.Properties.Settings.Default.Save();
            
            ClsConnection.Conn = null;
            this.Close();
        }

        private void btnArr_btnEventClose_click(object sender, EventArgs e)
        {

        }

        private void FrmChSQL_Load(object sender, EventArgs e)
        {
            txtHost.Text = ClsConnection.Server;
            txtUsename.Text = ClsConnection.Username;
            txtCsdl.Text = ClsConnection.Database;
            btnArr.btnSua.Text = "Đồng ý";
        }
    }
}